<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/8/31 0031
  Time: 14:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8"/>
  <title></title>
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
  <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
  <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>

</head>
<div class="row">
  <div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title" id="index-page-title" style="font: normal 30px/0.8em '微软雅黑'">孜点教科</h3>
    <ul class="page-breadcrumb breadcrumb">
      <%--<li>
      <i class="fa fa-home"></i>
      首页
      <i class="fa fa-angle-right"></i>
      </li>--%>
      <li>
        老师管理
        <i class="fa fa-angle-right"></i>
      </li>
      <li>
        <%--<a href="javascript:;">--%>
        查看老师
        <%--</a>--%>
      </li>
    </ul>
    <!-- END PAGE TITLE & BREADCRUMB-->
  </div>
</div>

<input class="easyui-searchbox" data-options="prompt:'请输入教师编号或教师名字或教师职务职务或教师身份证 查询',searcher:doSearch" style="width:450px;height: 48px;background: transparent;border:none;">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'是否要删除当前所选择的老师'" style="width: 400px;">
  <div style="width:368px;height:160px;margin:auto;" >
       <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delTeacher()" style="display:inline-block;width:120px;height:30px;margin:65px 0px 0px 122px;line-height:30px;">确认删除当前老师</a>
  </div>
</div>
<table id="dg" title="老师信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
  <thead>
  <tr>
    <th field="teacherId" width="100">教师编号</th>
    <th field="teacherName" width="100">教师名字</th>
    <th field="teacherSex" width="50">教师性别</th>
    <th field="teacherIdCard" width="200">教师身份证</th>
    <th field="teacherPhoneNumber" width="100">教师电话号码</th>
    <th field="teacherPosition" width="100">教师职称</th>
    <th field="teacherRanking" width="100">排名</th>
    <th field="mySum" width="100">分数</th>
    <th field="beViewed" width="100">被阅读数</th>
    <th field="beComments" width="100">被评价数</th>
    <th field="teacherSchool" width="200">教师学校</th>
    <th field="teacherCollege" width="200">教师学院</th>
    <th field="myBirthd" width="150">生日</th>
    <th field="myNickName" width="100">App昵称</th>
    <th field="personalizedSignature" width="200">App个性签名</th>
  </tr>
  </thead>
</table>
<div id="test1" class="easyui-dialog" data-options="closed:true,modal:true,title:'修改教师的信息'" style="width:400px">
  <form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
    <table style="margin:0px auto;margin-top: 20px;">
     <input type="hidden" name="teacherId" id="teacherId">
      <tr>
        <td>教师名字:</td>
        <td><input class="easyui-validatebox" name="teacherName"id="teacherName"
                   data-options="validType:'text',required:true,missingMessage:'不能为空！',validType:'length[1,20]',invalidMessage:'长度请不要大于20'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>教师性别:</td>
        <td><select class="easyui-combobox" name="teacherSex" id="teacherSex" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;">
          <option value="男">男</option>
          <option value="女">女</option>
        </select></td>
      </tr>
      <tr>
        <td>教师职称:</td>
        <td><input class="easyui-validatebox" name="teacherPosition" id="teacherPosition"
                   data-options="validType:'text',required:true,missingMessage:'不能为空！',validType:'length[1,20]',invalidMessage:'长度请不要大于20'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>教师电话:</td>
        <td><input class="easyui-validatebox" name="teacherPhoneNumber" id="teacherPhoneNumber"
                   data-options="validType:'mobile',required:true,missingMessage:'不能为空！'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>教师身份证:</td>
        <td><input class="easyui-validatebox" name="teacherIdCard" id="teacherIdCard"
                   data-options="validType:'text',required:true,missingMessage:'不能为空！',validType:'idCode',invalidMessage:'身份证格式不正确'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>教师学院:</td>
        <td><input class="easyui-validatebox" name="teacherCollege" id="teacherCollege"
                   data-options="validType:'text',required:true,missingMessage:'不能为空！',validType:'length[1,20]',invalidMessage:'长度请不要大于20'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>教师学校:</td>
        <td><input class="easyui-validatebox" name="teacherSchool" id="teacherSchool"
                   data-options="validType:'text',required:true,missingMessage:'不能为空！',validType:'length[1,20]',invalidMessage:'长度请不要大于20'" style="width:200px;height:30px; border:1px solid #d6dde5;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
    </table>
    <input type="hidden" value="${user.teacherid }" name="manageId">
  </form>
  <div style="text-align:center;padding:5px">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:116px;height:30px;margin-bottom: 20px;">提交</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()" style="width:116px;height:30px;margin-bottom: 20px;">清除</a>
  </div>
</div>
<script>
  var i = 1;
  function pagerFilter(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  $(function(){
    $('#dg').datagrid({
      toolbar:[
        {
        text:'删除所选中的一条信息',
        iconCls:'icon-remove',
        handler:function(){
          $('#test').window('open');
        }
      },
        {
          text:'修改所选择的一条信息',
          iconCls:'icon-search',
          handler:function(){
            $('#test1').window('open');
            var row = $('#dg').datagrid('getSelected');
            $("#teacherId").val(row.teacherId);
            $("#teacherCollege").val(row.teacherCollege);
            $("#teacherName").val(row.teacherName);
            $("#teacherSex").val(row.teacherSex);
            $("#teacherPosition").val(row.teacherPosition);
            $("#teacherPhoneNumber").val(row.teacherPhoneNumber);
            $("#teacherIdCard").val(row.teacherIdCard);
            $("#teacherSchool").val(row.teacherSchool);
          }
        }
      ]
    })
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
  });


  function delTeacher(){
    var row = $('#dg').datagrid('getSelected');
    if (delData(row.teacherId)==200){
      var index = $('#dg').datagrid('getRowIndex', row);
      $('#test').window('close');
      $('#dg').datagrid('deleteRow', index);
    }else{
      alert("删除失败")
    }
  }

  function delData(s){
    var code1 = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/manageTea/delOneTea',
      data: 'manageId=${user.teacherid }&teacherId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error');
      }
    });
    return code1
  }

  function getData(r,p,s){
    var infor_data = [];
    var total = 0;
    $.ajax({
      method : 'post',
      url : 'rest/page/manageTea/select',
      data:'startrow='+r+'&pageSize='+p+'&teacherId='+s+'&manageId=${user.teacherid }',
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data = data.data
        total = data.total
      },
      error : function() {
        alert('error');
      }

    });
    var rows = [];
    if(infor_data!=null) {
      for (var i = 0; i < infor_data.length; i++) {
        rows.push({
          total: total,
          wh: s,
          teacherId: infor_data[i].teacherId,
          teacherCollege: infor_data[i].teacherCollege,
          teacherIdCard: infor_data[i].teacherIdCard,
          teacherName: infor_data[i].teacherName,
          teacherPhoneNumber: infor_data[i].teacherPhoneNumber,
          teacherPosition: infor_data[i].teacherPosition,
          teacherSchool: infor_data[i].teacherSchool,
          teacherSex: infor_data[i].teacherSex,
          myBirthd: infor_data[i].myBirthd,
          myNickName: infor_data[i].myNickName,
          personalizedSignature: infor_data[i].personalizedSignature,
          beViewed: infor_data[i].beViewed,
          beComments: infor_data[i].beComments,
          teacherRanking: infor_data[i].teacherRanking,
          mySum: infor_data[i].mySum
        });
      }
    }
    return rows;
  }

  function doSearch(value){
    i = 1;
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value));
  }

  function submitForm() {
    $('#ff').form('submit', {
      url : 'rest/page/manageTea/updTea',
      onSubmit: function () {
        return $(this).form('enableValidation').form('validate');
      },
      success : function(data){
        var obj = JSON.parse(data)
        if(obj.code == 200){
          $.messager.show({title:'操作提示',msg:obj.message+"请刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
          $('#test1').window('close');
        }else{
          $.messager.show({title:'操作提示',msg:obj.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      }
    });
  }
  function clearForm() {
    $('#ff').form('clear');
  }

  $.extend($.fn.validatebox.defaults.rules, {
    CHS: {
      validator: function (value, param) {
        return /^[\u0391-\uFFE5]+$/.test(value);
      },
      message: '请输入汉字'
    },
    mobile: {
      validator: function (value, param) {
        return /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/.test(value);
      },
      message: '手机号码不正确'
    },
    idCode:{
      validator:function(value,param){
        return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value);
      },
      message: '格式不正确'
    }
  });
</script>
</body>
</html>
